/*************************************************
Author: byron
Date: 10/16/2012
Description:
Notes: 
*************************************************/

#ifndef __CPartnerMgr_h__
#define __CPartnerMgr_h__

#include "CPartnerCfg.h"
#include "MsgPartner.pb.h"

class MsgReqGMPlayer;
class MsgAnsGMPlayer;
class MsgAnsActPartner;
class MsgAnsPartner;
class MsgGridItemInfo;
class CSkillMgr;
class CUserPartner;
class CPlayerBaseInfo;
class CPlayerDetailInfo;
class CPlayerOnlineData;
class CUnactPartnerInfo;
class CPlayerDetailInfoEx1;
class CPartnerMgr
{
public:
    enum CMD_PARTNER_SUB_MAP
    {
        CMD_PARTNER_SUB_ACT = 1,
        CMD_PARTNER_SUB_LIST = 2,
        CMD_PARTNER_SUB_JOIN = 3,
        CMD_PARTNER_SUB_SIGN = 4,
        CMD_PARTNER_SUB_LOCK = 5,
        CMD_PARTNER_SUB_LEAVE = 6,
        CMD_PARTNER_SUB_RECALL = 7,
        CMD_PARTNER_SUB_GET_CONDITION = 8,
    };

    enum CMD_PARTNER_JOIN_TYPE
    {
        PARTNER_JOIN_TYPE_NORMAL = 1,//客户端发起的招募类型
        PARTNER_JOIN_TYPE_SYSTEM = 2,//服务端发起的招募类型
    };

    enum PARTNER_NOTIFY_MASK
    {
        PARTNER_NOTIFY_ACT = 0x1,   //激活伙伴列表下发
        PARTNER_NOTIFY_LIST = 0x2,  //历史伙伴列表下发
    };

    CPartnerMgr()
    {
        Clear();
    }
    void Clear()
    {
        _shFirstPayPartner = 0;
        _iRoleReputationLimit = 0;
    }

    virtual ~CPartnerMgr() 
    {
    }

    int LoadConfig(const char* szLogPath);

    bool IsValidJoinType(int iType)
    {
        return (PARTNER_JOIN_TYPE_NORMAL == iType ||
                PARTNER_JOIN_TYPE_SYSTEM == iType);
    }

    int AddPartnerCfg(CPartnerCfgData& stCfgData);
    int FindPartnerCfg(short shResID);

    CPartnerCfgData& GetPartnerCfg(int iIndex);

    int GetPartnerCfg(short shResID, CPartnerCfgData& stCfgData);

    int GetPartnerFighting(short shResID, CPlayerOnlineData& stPlayerOnline);

    int InitPartnerOnlineData(CPlayerBaseInfo& stPlayerBase,
            CPlayerDetailInfo& stPlayerDetail,
            CPlayerOnlineData& stPlayerOnline,
            CPlayerDetailInfoEx1& stPlayerDetailEx1);

    int CalcExtAttr(CPartnerCfgData& stCfgData, CPlayerAttr& stPartnerAttr,
            short shLevel, bool bCalcExtAttr = false);

    int CalcPartnerFavor(short shResID, int iFavor, int& iFavorRate);

    int PartnerGetActCard(MsgAnsActPartner& pstOneAct,
            CPlayerOnlineData& stPlayerOnline,
            CPlayerDetailInfo& stPlayerDetailInfo, CPartnerUnit& stPartnerUnit);

    int PartnerGetOneAct(CPartnerActData& stActData,
            CPartnerUnit& stPartnerUnit, MsgAnsActPartner& stMsgActPartner,
            CPlayerOnlineData& stPlayerOnline,
            CPlayerDetailInfo& stPlayerDetail, CPlayerBaseInfo& stPlayerBase);

    int PartnerGetOneAct(CPlayerOnlineData& stPlayerOnline,
            CPlayerDetailInfo& stPlayerDetail, CPlayerBaseInfo& stPlayerBase,
            MsgAnsActPartner& stMsgActPartner, short shResID);

    int PartnerGetJoinWay(CPlayerBaseInfo& stPlayerBase,
            CPlayerOnlineData& stPlayerOnline, MsgAnsPartner& stAns);

    int PartnerGetAct(CPlayerOnlineData& stPlayerOnline,
            CPlayerDetailInfo& stPlayerDetail, CPlayerBaseInfo& stPlayerBase,
            MsgAnsPartner& stAns, short shResID = 0);

    int PartnerGetAct(CPlayerOnlineData& stPlayerOnline,
            CPlayerDetailInfo& stPlayerDetail, CPlayerBaseInfo& stPlayerBase,
            ::google::protobuf::RepeatedPtrField<MsgAnsActPartner>& stActPartners,
            short shResID = 0);

    int PartnerGetOneList(CPartnerListData& stPartnerList,
            MsgAnsListPartner& stMsgListPartner);

    int PartnerGetList(CUnactPartnerInfo& stUnactPartnerInfo,
            ::google::protobuf::RepeatedPtrField<MsgAnsListPartner>& stListPartners,
            short shResID = 0);

    int NotifyPartner(unsigned int uiGID, int iNotifyMask);

    int PartnerGetJoinWay(CPlayerBaseInfo& stPlayerBase, MsgAnsPartner& stAns);

    int PartnerJoinFirstPay(CPlayerBaseInfo& stPlayerBase,
            CPlayerDetailInfo& stPlayerDetail,
            CUnactPartnerInfo& stUnactPartnerInfo,
            CPlayerOnlineData& stPlayerOnline,
            CPlayerDetailInfoEx1& stPlayerDetailEx1);

    int PartnerJoinUseItem(short shResID, CPlayerBaseInfo& stPlayerBase,
            CPlayerDetailInfo& stPlayerDetail,
            CUnactPartnerInfo& stUnactPartnerInfo,
            CPlayerOnlineData& stPlayerOnline,
            CPlayerDetailInfoEx1& stPlayerDetailEx1);

    bool IsRoleGetPartner(short shResID,
            CPlayerDetailInfo& stPlayerDetail,
            CUnactPartnerInfo& stUnactPartnerInfo);

    int CheckPartnerJoin(short shResID, int iJoinType,
            CPlayerBaseInfo& stPlayerBase, CPlayerDetailInfo& stPlayerDetail,
            CUnactPartnerInfo& stUnactPartnerInfo,
            CPlayerOnlineData& stPlayerOnline);

    int PartnerJoin(short shResID, int iJoinType, CPlayerBaseInfo& stPlayerBase,
            CPlayerDetailInfo& stPlayerDetail,
            CUnactPartnerInfo& stUnactPartnerInfo,
            CPlayerOnlineData& stPlayerOnline,
            CPlayerDetailInfoEx1& stPlayerDetailEx1, MsgAnsPartner& stAns);

    int PartnerSign(short shResID, CPlayerBaseInfo& stPlayerBase,
            CPlayerDetailInfo& stPlayerDetail,
            CPlayerOnlineData& stPlayerOnline,
            CPlayerDetailInfoEx1& stPlayerDetailEx1, MsgAnsPartner& stAns);

    int PartnerLock(short shResID, CPlayerBaseInfo& stPlayerBase,
            CPlayerDetailInfo& stPlayerDetail,
            CPlayerOnlineData& stPlayerOnline,
            CPlayerDetailInfoEx1& stPlayerDetailEx1, MsgAnsPartner& stAns);

    int PartnerLeave(short shResID, CPlayerBaseInfo& stPlayerBase,
            CPlayerDetailInfo& stPlayerDetail,
            CUnactPartnerInfo& stUnactPartnerInfo,
            CPlayerOnlineData& stPlayerOnline, MsgAnsPartner& stAns);

    int PartnerRecall(short shResID, CPlayerBaseInfo& stPlayerBase,
            CPlayerDetailInfo& stPlayerDetail,
            CUnactPartnerInfo& stUnactPartnerInfo,
            CPlayerOnlineData& stPlayerOnline,
            CPlayerDetailInfoEx1& stPlayerDetailEx1, MsgAnsPartner& stAns);

    int PartnerChkActStat(short shResID, CPlayerOnlineData& stPlayerOnline);

    int PartnerChkEquipStat(short shResID, CPlayerDetailInfo& stPlayerDetail,
            CPlayerOnlineData& stPlayerOnline, unsigned int uiEquipID,
            int iPos);

    int PartnerWearEquip(short shResID, CPlayerBaseInfo& stPlayerBase,
            CPlayerDetailInfo& stPlayerDetail,
            CPlayerOnlineData& stPlayerOnline, unsigned int uiEquipID,
            int iPos);

    int PartnerTakeOffEquip(short shResID, CPlayerBaseInfo& stPlayerBase,
            CPlayerDetailInfo& stPlayerDetail,
            CPlayerOnlineData& stPlayerOnline, unsigned int uiEquipID,
            int iPos);

    int GMDealPartner(CPlayerBaseInfo& stPlayerBase,
            CPlayerDetailInfo& stPlayerDetail,
            CPlayerOnlineData& stPlayerOnline,
            CUnactPartnerInfo& stUnactPartnerInfo,
            CPlayerDetailInfoEx1& stPlayerDetailEx1, MsgReqGMPlayer& stReq,
            MsgAnsGMPlayer& stAns);

    int PartnerUpLevel(short shResID, CPlayerBaseInfo& stPlayerBase,
            CPlayerDetailInfo& stPlayerDetail,
            CPlayerOnlineData& stPlayerOnline,
            CPlayerDetailInfoEx1& stPlayerDetailEx1);

    int PartnerAddExp(short shResID, int iAddExp,
            CPlayerBaseInfo& stPlayerBase, CPlayerDetailInfo& stPlayerDetail,
            CPlayerOnlineData& stPlayerOnline,
            CPlayerDetailInfoEx1& stPlayerDetailEx1);

    int UnactPartnerAddExp(short shResID, int iAddExp,
            CPlayerBaseInfo& stPlayerBase,
            CUnactPartnerInfo& stUnactPartnerInfo);

    int DealUpLevel(short& shLevel, short shRoleLevel, int64 i64AddExp,
            int64& i64Exp);

    short GetFirstPayPartner();

    int GetRoleReputationLimit() const {return _iRoleReputationLimit;}
private:
    void SetFirstPayPartner(short shVal)
    {
        _shFirstPayPartner = shVal;
    }
    void SetRoleReputationLimit(int iVal)
    {
        _iRoleReputationLimit = iVal;
    }

private:
    short _shFirstPayPartner;
    int _iRoleReputationLimit;
    CPartnerCfg _stPartnerCfg;
};

#endif // __CPartnerMgr_h__


